﻿/* Cached from: js/demo.js on Tue, 20 Mar 2012 10:17:20 -0700 */

$(document).ready(function() {
var a = $(".nav"), b = $("#demoframe"), g = $("#jsddm", a), i = $("#contentheader .toolbar"), j = $(".demo-description", a), h = $("#contentheader h2"), c = document.title, k = 0, f = "Choose a demo from above", e = document.location.href.match(/#([\w-]+)$/i);
    e = e && e.length ? e[1] : null;
    function d() {
        var l = $("body", $("iframe:visible", b).contents()).height() + 30;
        a.height(Math.max(680, l))
    }
    $("iframe.demo", a).load(function() {
        $("#loading").fadeOut(400);
        d()
    });
    i.delegate(".button:not(.source):not(.fiddle)", "mousedown mouseup mouseleave", function(l) {
        l.preventDefault();
        $(this).toggleClass("active", l.type === "mousedown")
    });
    $(".popout", i).click(function() {
        var n = 1000, l = 650, p = parseInt((screen.availWidth / 2) - (n / 2)), o = parseInt((screen.availHeight / 2) - (l / 2)), m = "width=" + n + ",height=" + l + ",status,resizable,left=" + p + ",top=" + o + "screenX=" + p + ",screenY=" + o;
        window.open($("iframe:visible", a).attr("src"), "qtipdemo", m);
        return false
    });
    $(".source", i).mousedown(function() {
        $("iframe", b).toggle();
        d();
        $(this).toggleClass("active");
        return false
    }).click(false);
    $(".download", i).click(function() {
        window.location = $("iframe.demo", a).attr("src") + "?download";
        return false
    }).click(false);
    $(".fiddle", i).attr("target", "_blank");
    $(window).bind("resize", function() {
        b.width($(this).width() - g.outerWidth() - 1)
    }).triggerHandler("resize");
    $("li", g).each(function(m, n) {
        var l = $(this);
        l.toggleClass("odd", !!(l.index() % 2))
    }).find("[title]").qtip({
        position: {
            target: "mouse",
            adjust: {
                mouse: false,
                x: 5,
                y: 5
            }
        },
        show: {
            delay: 600,
            solo: a
        },
        hide: {
            event: "mouseleave click",
            distance: 15
        },
        style: {
            tip: false
        }
    });
    g.delegate("li a", "click", function(o) {
        var m = $(this), n = m.parent().index(), l = m.attr("href"), q = l.match(/\/([\w-]+)\/?$/i), p = document.location.hash, r = m.attr("rel");
        if (!$(this).hasClass("active")) {
            $("#loading", a).fadeIn(100, function() {
                $("iframe", a).attr("src", function(s, t) {
                    return l + ($(this).hasClass("source") ? "?source" : "")
                });
                if ($("iframe.source:visible", a).length) {
                    $(".source", i).trigger("mousedown")
                }
                d();
                j.html(f = m.attr("title"));
                document.title = c + " - " + m.text();
                h.html("Demos - " + m.text());
                if (q && q[1] === "simple") {
                    if (p) {
                        document.location.hash = ""
                    }
                } else {
                    if (q && q.length) {
                        document.location.hash = q[1]
                    }
                }
            });
            $(".fiddle", i).toggle(!!r).attr("href", "http://jsfiddle.net/craga89/" + r);
            $("li", g).removeClass("active");
            m.parent().addClass("active")
        }
        o.preventDefault()
    });
    hashLink = $("li a" + (e ? "[href$=" + e + "]" : ":eq(" + k + ")"), g);
    hashLink.trigger("click");
    $(".accordion", g).accordion({
        active: hashLink.parents("ul").index("ul") - 1
    })
});
